home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
DJGPP
/
DJSRC111.ZIP
/
utils
/
dpmifix.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-31
|
2KB
|
83 lines
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#define BUFSIZE 16384
#ifndef O_BINARY
#define O_BINARY 0
#endif
#include "readspat.h"
main(argc, argv)
int argc;
char **argv;
{
char *buffer;
int patchlen,npend,i,j,k,l,buflen;
int fil,nread;
long where;
FILE *fp;
int wild_in_prog, done;
char *wildname, *dire, *cp;
char nbuf[132];
/* struct ffblk ff; */
patchlen = sizeof(original);
buffer = (char *)malloc(BUFSIZE + patchlen);
wild_in_prog = 0;
loop:
if(!wild_in_prog) {
argv++;
argc--;
/* if(strpbrk(argv[0],"*?")) {
done = findfirst(argv[0], &ff, FA_RDONLY|FA_DIREC|FA_ARCH);
if(!done) {
wild_in_prog = 1;
wildname = argv[0];
strcpy(nbuf, wildname);
for (dire=cp=nbuf; *cp; cp++)
if (strchr("/\\:", *cp))
dire = cp + 1;
strcpy(dire, ff.ff_name);
argv[0] = &nbuf;
}
} */
} else {
/* done = findnext(&ff);
if(done) {
wild_in_prog = 0;
goto loop;
}
strcpy(dire, ff.ff_name); */
}
if(!argc)exit(0);
npend = 0;
fil = open(argv[0], O_RDWR|O_BINARY, 0);
if(fil < 0) {
fprintf(stderr,"%s not found.\n",argv[0]);
goto loop;
}
where = 0;
nread = read(fil, buffer, BUFSIZE);
while (nread > 0) {
buflen = nread + npend;
i = dopatch(buffer, buflen, original, match, patch, patchlen, &npend);
if (i >= 0) {
where = lseek(fil, (long)where+i, SEEK_SET);
write(fil, buffer+i, npend);
close(fil);
goto loop;
}
if (npend) memcpy(buffer, buffer+buflen-npend, npend);
where = lseek(fil, 0L, SEEK_CUR) - npend;
nread = read(fil, buffer+npend, BUFSIZE);
}
close(fil);
fprintf(stderr,"Patch code not found in %s\n",argv[0]);
goto loop;
}